home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / b2obj11b.zip / TEST.C < prev    next >
Text File  |  1994-06-11  |  4KB  |  128 lines

  1. /* ----------------------------------------------------------- *\
  2.  
  3.    TEST.C      version 1.10b
  4.    (c) Copyright 1994 Heng Yuan.
  5.  
  6.    You are granted to modify this file any way you wish.
  7.    This code is provided "AS IS", without any warranty.
  8.  
  9.    This is a demo of ACA Bin2Obj 1.10b.  The beauty of linking
  10.    graphics and text files into the executable is that there
  11.    are absolutely no need to write codes to find these files
  12.    and read them in at run time.  This also makes the finished
  13.    product look more compact.
  14.  
  15.    Since this program is just a demonstration, lots of codes
  16.    in this program are directly copied from the Borland C++
  17.    help file which is very good at this.
  18.  
  19. \* ----------------------------------------------------------- */
  20.  
  21. #include <alloc.h>
  22. #include <conio.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <graphics.h>
  26.  
  27. /* include text file */
  28. extern unsigned char IntroText[];
  29. /* include intro picture */
  30. extern unsigned char IntroPict[];
  31.  
  32. /* ----------------------------------- *\
  33.   this code is used to detect VGA
  34.   adapter.  Copied from help file
  35.   with slight modifications
  36. \* ----------------------------------- */
  37. int huge detectVGA (void)
  38. {
  39.   int driver, mode, sugmode = 0;
  40.  
  41.   detectgraph (&driver, &mode);
  42.   if (driver == VGA)
  43.     /* return suggested video mode number */
  44.     return sugmode;
  45.   else
  46.     /* return an error code */
  47.     return grError;
  48. }
  49.  
  50. /* ----------------------------------- *\
  51.   this code is used to detect VGA
  52.   adapter.  No modifications
  53. \* ----------------------------------- */
  54. /* check for and report any graphics errors */
  55. void checkerrors (void)
  56. {
  57.   int errorcode;
  58.  
  59.   /* read result of last graphics operation */
  60.   errorcode = graphresult();
  61.   if (errorcode != grOk)
  62.     {
  63.       printf ("Graphics error: %s\n", grapherrormsg (errorcode));
  64.       printf ("Press any key to halt:");
  65.       getch ();
  66.       exit (1);
  67.     }
  68. }
  69.  
  70. void main ()
  71. {
  72.   int  gdriver = 0, gmode = 0;
  73.  
  74.   /*
  75.     To display a graphics file, the video mode must be switched to
  76.     graphics.  The graphics file used in this example requires 256
  77.     color, so the most portable mode is 320x200x256c using VGA256.BGI.
  78.     The setup is according to the Borland Help file examples.
  79.   */
  80.   /* install a user written device driver */
  81.   gdriver = installuserdriver("SVGA256", detectVGA);
  82.   /* must force use of detection routine */
  83.   gdriver = DETECT;
  84.   /* check for any installation errors */
  85.   checkerrors();
  86.   /* initialize graphics and local variables */
  87.   initgraph(&gdriver, &gmode, "");
  88.  
  89.   /*
  90.      The bitmap image was originally created using NeoPaint
  91.      and saved in .PCX file extension.  Then used MVPPAINT
  92.      to convert the .PCX to .VGA.  The file was then inserted
  93.      into .OBJ.  Note that SVGA256.BGI is used instead of
  94.      VGA256.BGI.  This is because MVPPAINT VGA format is
  95.      compatible with SVGA256.BGI.  The image data format of
  96.      VGA256.BGI is slightly different from SVGA256.BGI.
  97.      BTW, SVGA256.BGI can also be used to display mode 0x13.
  98.   */
  99.   putimage (0, 0, IntroPict, COPY_PUT);
  100.  
  101.   getch ();
  102.  
  103.   closegraph ();
  104.  
  105.   /*
  106.      Since dos text files have LF and CR as goto the first column of a
  107.      new line, and because most C string only have LF as the return,
  108.      Borland C lib automatically adds CR before each LF.  And since dos
  109.      editors all add CR before LF, the result is there are two CR before
  110.      every LF are actually written on screen.  You won't discover that
  111.      there are two CR unless the the output has been redirected to a text
  112.      file and viewed through a text file viewer such as the famous LIST,
  113.      the text file looks double spaced. This is because CR in dos is
  114.      interpreted as placing the cursor to the first column.  Yet many
  115.      text file viewers simply take CR as the carriage return and do not
  116.      actually process LF.  Thus the redirected text file looks double
  117.      spaced.  For the best result, one can take a utility that striple
  118.      CR out of the text file.
  119.  
  120.      Another reminder, the text file needs to be ended with character
  121.      \x00 so that puts or printf can understand when to stop putting
  122.      characters on screen.
  123.  
  124.      The text file was created using the DOS EDIT.
  125.   */
  126.   puts (IntroText);
  127. }
  128.